<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Contact extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model("client_model");
    }

    public function show_html() {

        $html["i"] = $this->input->post('count');
        $this->load->view('client/contact_table', $html);
    }

    public function insert_contact_submit() {


        if (count($_POST) > 0) {

            $ref_client_verify_code = $_POST['ref_client_verify_code'];
            foreach ($_POST['contact'] as $key => $value) {
                $this->client_model->insert_contact($value, $ref_client_verify_code);
            }
        }
    }

    public function data_update_submit() {


        $this->load->model("client_model");





        foreach ($_POST['contact'] as $key => $value) {

            if (!empty($value["contact_id"])) {
                //更新
                $data = array('name' => $value["name"],
                    "english_name" => $value["english_name"],
                    "sex" => $value["sex"],
                    "mobile" => $value["mobile"],
                    "home_phone" => $value["home_phone"],
                    "company_phone" => $value["company_phone"],
                    "fax" => $value["fax"],
                    "home_address" => $value["home_address"],
                    "company_address" => $value["company_address"]);

                $this->client_model->update_contact($data, $value["contact_id"]);
            } else {

                //輸入
                //print_r($value);
                $value["ref_client_verify_code"] = $_POST["ref_client_verify_code"];
                $this->client_model->demand_insert_contact($value);
            }
        }
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
